﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        private void Register_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            var userName = textBox1.Text;
            var passWord = textBox2.Text;
            var repassWord = textBox3.Text;

            var user = !string.IsNullOrEmpty(userName);
            var wed = !string.IsNullOrEmpty(passWord);
            var rewed = passWord == repassWord;

            if (user && wed && rewed && (textBox4.Text .Length >=6))
            {
                MessageBox.Show("恭喜你！注册成功!");
                Form1.users.Add(userName, passWord);
                this.Show();
                //关闭当前窗口
                this.Close();
            }
            else if (textBox1.Text == "")
            {
                MessageBox.Show("请输入用户名：", "注册失败");
                textBox1.Focus();
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("请输入密码：", "注册失败");
                textBox2.Focus();
            }
            else if (textBox3.Text == "")
            {
                MessageBox.Show("请确认密码哦！！！", "注册失败");
                textBox3.Focus();
            }
            else if(textBox4 .Text == "")
            {
                MessageBox.Show("请补充完再确认！！！", "注册失败");
                textBox4.Focus();
            }
            else
            {
                MessageBox.Show("注册失败","疯狂提示");
            }
          /*  if (textBox4.Text.Length < 6)
            {
                MessageBox.Show("请输入邮箱！", "提示！");
                return;
            }*/
        }
        /// <summary>
        /// 返回登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();   //关闭当前窗口
        }
        /// <summary>
        /// 判断邮箱是否正确
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            int index = textBox4.Text.IndexOf("@");
            if(index < 1)
            {
                label4.Text = "格式正确，疯狂提示！";
            }
            else
            {
                label4.Text = "邮箱格式正确！";
            }
        }

        private void label4_Click(object sender, EventArgs e)
        {
           // this.Close();   //关闭当前窗口
        }
    }
}
